/**
 * 
 */
package com.desksoft.ecommerce.handler.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.desksoft.ecommerce.constants.Constants;
import com.desksoft.ecommerce.helper.CookieHelper;
import com.desksoft.ecommerce.helper.ParamterAppendHelper;
import com.desksoft.utility.uuid.IDGenerator;

/***************************************
 * <pre>
 * 版权所有：杭州迪科软件 保留所有权利
 * 创建日期: Jun 22, 2011 3:51:01 PM
 * 创建作者：yejw
 * 文件名称：ParamterAppendInterceptor.java
 * 版本：
 * 功能：
 * 最后修改时间：Jun 22, 2011 3:51:01 PM
 * 修改记录：
 * </pre>
 *****************************************/

public class ParamterAppendInterceptor extends AbstractInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		String cookieUuid = CookieHelper.getCookieValue(request, Constants.COOKIE_UUID);
		if (cookieUuid == null) {
			cookieUuid = IDGenerator.get();
			CookieHelper.addCookie(response, Constants.COOKIE_UUID, cookieUuid);
		}
		request.setAttribute(Constants.COOKIE_UUID, cookieUuid);
		return true;
	}
	
	
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		//TODO, 后面排错
		try{
			if (modelAndView != null) {
				ParamterAppendHelper.paramAppend(request, modelAndView.getModelMap());
			}
		}catch (Exception e) {
			e.printStackTrace();
		}

		super.postHandle(request, response, handler, modelAndView);
	}

}
